﻿// Copyright (c) MichaConrad. All rights reserved. See License.txt in the project root for license information.

namespace LinqToLdapExtensions.Domain
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.DirectoryServices.Protocols;
    using System.Net;
    using LinqToLdap;
    using LinqToLdap.Logging;
    using LinqToLdap.Mapping;

    [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed. Suppression is OK here.")]
    public class DomainSetup
    {
        private const string ServerName = "127.0.0.1:389";
        public const string ServerRoot = "dc=unit,dc=test";
        public const string UserDirectoryContainer = "ou=People," + ServerRoot;

        public static LdapConfiguration SetupConfiguration()
        {
            var configuration = new LdapConfiguration()
                 ////.UseStaticStorage()
                 .LogTo(new SimpleTextLogger(Console.Out) { TraceEnabled = true })
                 .AddMapping(new AttributeClassMap<InetOrgPerson>(), UserDirectoryContainer);

            configuration.ConfigurePooledFactory(ServerName)
                .AuthenticateBy(AuthType.Basic)
                .AuthenticateAs(new NetworkCredential("cn=Directory Manager", "1431"))
                .MaxPoolSizeIs(1000);
            
            return configuration;
        }
    }
}
